//
//  ActivityViewArticleCell.swift
//  iModern
//
//  Created by Ralf on 15/5/14.
//  Copyright (c) 2015年 com.starlooking. All rights reserved.
//

import UIKit

class ActivityViewArticleCell: ArticleCell
{
    var activity: NSMutableDictionary!
    override func awakeFromNib()
    {
        super.awakeFromNib()
    }

    func setData(data: NSMutableDictionary)
    {
        activity = data
        let article = data["article"] as! NSMutableDictionary
        let contact = article["contact"] as! NSDictionary

        setAliasLabel(contact["alias"] as! String)
        setNumberOfFavoritesButton(String(article["numberOfFavorites"] as! Int))
        setNumberOfCommentsButton(String(article["numberOfComment"] as! Int))
        setAvatarImageView(contact["thumbnailURL"] as? String)
        setPreviewImageView(article["imageURL"] as! String)
        setMessageTextView(article["message"] as! String)
    }

    override func setSelected(selected: Bool, animated: Bool)
    {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }

    @IBAction func favorites(sender: AnyObject)
    {
        if !appDelegate.isLogged()
        {
            login()
        }
        else
        {
            let button = self.viewWithTag(0) as! UIButton

            if !button.selected
            {
                activity["favorites"] = true
                let favoritesManager = FavoritesManager()
                let article          = activity["article"] as! NSDictionary
                let articleId        = String(article["id"] as! Int)
                favoritesManager.addFavorites(articleId)
                button.selected = true
            }
        }
    }
}
